#include "nane/testframework/androidmain.h"

#include "nane/testframework/testframework.h"

#include <android/log.h>
#include "nane/core/ILogger.h"

static const android_LogPriority naneLogPriorityToAndoid[nane::ELogMessageLevel::size] =
{
    ANDROID_LOG_ERROR,
    ANDROID_LOG_WARN,
    ANDROID_LOG_INFO,
    ANDROID_LOG_DEBUG
};
class AndroidLogger
    : public nane::ILogger
{
public:
    void log( const char* _message, const char* _file, const char* _line
                    , const char* _function, nane::ELogMessageLevel::raw_type _messageLevel )
    {
        __android_log_write(naneLogPriorityToAndoid[_messageLevel], "nane", _message);
    }
};

static nane::TestFramework* g_testFramework = NULL;
static AndroidLogger logger;

JNIEXPORT void JNICALL Java_nane_android_test_DemoRenderer_nativeOnCreate( JNIEnv* env, jobject thiz, jstring apkPath )
{
    const char* assetsPath;
    jboolean isCopy;
    assetsPath = env->GetStringUTFChars(apkPath, &isCopy);
  
    g_testFramework = nane::TestFramework::createTest();
    g_testFramework->initialize(assetsPath, &logger);
    g_testFramework->onSetup();
} 

JNIEXPORT void JNICALL Java_nane_android_test_TestMain_nativeOnDestroy( JNIEnv* env, jobject thiz )
{
    g_testFramework->onShutdown();
    g_testFramework->shutdown();
    nane::TestFramework::releaseTest(g_testFramework);
} 

JNIEXPORT void JNICALL Java_nane_android_test_DemoRenderer_nativeOnRender( JNIEnv* env, jobject thiz )
{
    if( g_testFramework != NULL )
    {
        g_testFramework->update();
    }
} 

